class SuppliersController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :supplier_list
    @title = '供应商'
    @suppliers = Supplier.all
  end

  def new
    @supplier = Supplier.new
  end

  def create
    @supplier = Supplier.new post_params
    if @supplier.save
      redirect_to suppliers_path
    else
      render :action => 'new'
    end
  end

  def edit
    @supplier = Supplier.find params[:id]
  end

  def update
    @supplier = Supplier.find params[:id]
    if @supplier.update_attributes post_params
      redirect_to suppliers_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @supplier = Supplier.find params[:id]
    @supplier.destroy
    redirect_to suppliers_path
  end


  def post_params
    params.require(:supplier).permit(*%w(name phone fax email addr tax_num note))
  end

  private
  def set_menu
    @mainmenu = :intercourse
  end
end
